package vip.xiaonuo.sys.fymodule.plugins.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import vip.xiaonuo.sys.fymodule.plugins.entity.SxoPluginsCertificateUserAuth;
import vip.xiaonuo.sys.fymodule.plugins.mapper.SxoPluginsCertificateUserAuthMapper;
import vip.xiaonuo.sys.fymodule.plugins.service.ISxoPluginsCertificateUserAuthService;

import java.util.List;

/**
 * 用户资质认证 - 资质认证 业务层实现
 *
 * @author wangy
 * @since 2025-06-11
 */
@Slf4j
@Service
public class SxoPluginsCertificateUserAuthServiceImpl extends ServiceImpl<SxoPluginsCertificateUserAuthMapper, SxoPluginsCertificateUserAuth> implements ISxoPluginsCertificateUserAuthService {


    @Override
    public SxoPluginsCertificateUserAuth findAuthByUserId(String userId, String uniqueKey, String title) {
        LambdaQueryWrapper<SxoPluginsCertificateUserAuth> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SxoPluginsCertificateUserAuth::getUserId, userId);
        queryWrapper.eq(SxoPluginsCertificateUserAuth::getUniqueKey, uniqueKey);
        queryWrapper.eq(SxoPluginsCertificateUserAuth::getStatus, "1");
        if (StrUtil.isNotEmpty(title)) {
            queryWrapper.eq(SxoPluginsCertificateUserAuth::getTitle, title);
        }
        queryWrapper.orderByDesc(SxoPluginsCertificateUserAuth::getId);
        List<SxoPluginsCertificateUserAuth> list = this.list(queryWrapper);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }
}